﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using System.Reflection;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.Windows;

namespace WlanDesignDll
{
    public class AcadWlan
    {
        [CommandMethod("AddToolBar")]
        public void AddToolBar()
        {
            //获取当前运行的程序集
            System.Reflection.Module myModule = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0];
            //获取当前运行的程序集的完整路径（包含文件名）
            string modulePath = myModule.FullyQualifiedName;
            //获取去除文件名后程序集的路径，即程序集所在的文件夹
            modulePath = modulePath.Substring(0, modulePath.LastIndexOf("\\"));
            //COM方式获取AutoCAD应用程序对象
            AcadApplication acadApp = (AcadApplication)Application.AcadApplication;
            //获取当前菜单组，用于加入工具栏
            AcadMenuGroup currMenuGroup = acadApp.MenuGroups.Item(0);
            //为AutoCAD添加一个新的工具栏，并设置标题为"我的工具栏"
            AcadToolbar tbModify = currMenuGroup.Toolbars.Add("我的工具栏");
            //在新建的工具栏中添加一个"AP"按钮，以调用AP命令
            AcadToolbarItem button0 = tbModify.AddToolbarButton("", "AP", "添加无线接入点", "_Copy", Type.Missing);
            //设置AP按钮的图片
            button0.SetBitmaps(modulePath + "\\Resources\\ap.bmp", modulePath + "\\Resources\\ap.bmp");
            //'添加一个"功分器"按钮，以调用功分器命令
            AcadToolbarItem button1 = tbModify.AddToolbarButton("", "功分器", "添加功分器", "_Erase", Type.Missing);
            //设置功分器按钮的图片
            button1.SetBitmaps(modulePath + "\\Resources\\gfq.bmp", modulePath + "\\Resources\\gfq.bmp");
            //添加一个"合路器"按钮，以调用合路器命令
            AcadToolbarItem button2 = tbModify.AddToolbarButton("", "合路器", "添加合路器", "_Move", Type.Missing);
            //设置合路器按钮的图片
            button2.SetBitmaps(modulePath + "\\Resources\\hlq.bmp", modulePath + "\\Resources\\hlq.bmp");
            //添加一个"耦合器"按钮，以调用耦合器命令
            AcadToolbarItem button3 = tbModify.AddToolbarButton("", "耦合器", "添加耦合器", "_Rotate ", Type.Missing);
            //设置耦合器按钮的图片
            button3.SetBitmaps(modulePath + "\\Resources\\ohq.bmp", modulePath + "\\Resources\\ohq.bmp");
            //添加一个"天线"按钮，以调用天线命令
            AcadToolbarItem button4 = tbModify.AddToolbarButton("", "天线", "添加天线对象", "_Rotate ", Type.Missing);
            //设置天线按钮的图片
            button4.SetBitmaps(modulePath + "\\Resources\\tx.bmp", modulePath + "\\Resources\\tx.bmp");

            //添加一个弹出按钮，该按钮只用来附着下面的画图工具栏
            AcadToolbarItem FlyoutButton = tbModify.AddToolbarButton("", "画图工具", "画图工具", " ", true);
            //创建第二个工具栏。该工具栏将通过弹出按钮附加到第一个工具栏。
            AcadToolbar tbDraw = currMenuGroup.Toolbars.Add("画图工具栏");
            //下面的语句分别在工具栏上设置绘制圆、直线、多段线、矩形的按钮
            AcadToolbarItem button5 = tbDraw.AddToolbarButton("", "圆", "用指定半径创建圆", "_Circle ", Type.Missing);
            button5.SetBitmaps(modulePath + "\\Resources\\Circle.bmp", modulePath + "\\Resources\\Circle.bmp");
            AcadToolbarItem button6 = tbDraw.AddToolbarButton("", "直线", "创建直线段", "_Line ", Type.Missing);
            button6.SetBitmaps(modulePath + "\\Resources\\Line.bmp", modulePath + "\\Resources\\Line.bmp");
            AcadToolbarItem button7 = tbDraw.AddToolbarButton("", "多段线", "创建二维多段线", "_Pline ", Type.Missing);
            button7.SetBitmaps(modulePath + "\\Resources\\Polyline.bmp", modulePath + "\\Resources\\Polyline.bmp");
            AcadToolbarItem button8 = tbDraw.AddToolbarButton("", "矩形", "创建矩形多段线", "_Rectangle ", Type.Missing);
            button8.SetBitmaps(modulePath + "\\Resources\\Rectangle.bmp", modulePath + "\\Resources\\Rectangle.bmp");
            //将第二个工具栏附着到第一个工具栏的弹出按钮上
            FlyoutButton.AttachToolbarToFlyout(currMenuGroup.Name, tbDraw.Name);
            //显示第一个工具栏
            tbModify.Visible = true;
            //隐藏第二个工具栏
            tbDraw.Visible = false;
        }

        // 增加WLAN自定义菜单
        [CommandMethod("AddApplicationMenuWLAN")]
        public void Initialize()
        {
            // We defer the creation of our Application Menu to when
            // the menu is next accessed
            ComponentManager.ApplicationMenu.Opening += new EventHandler<EventArgs>(ApplicationMenu_Opening);
        }

        public void ApplicationMenu_Opening(object sender, EventArgs e)
        {
            // Remove the event when it is fired
            ComponentManager.ApplicationMenu.Opening -= new EventHandler<EventArgs>(ApplicationMenu_Opening);

            // Add our Application Menu
            AddApplicationMenuItemWLAN();
        }

        public void AddApplicationMenuItemWLAN()
        {
            //获取应用菜单
            Autodesk.Windows.ApplicationMenu acAppMenu = Autodesk.Windows.ComponentManager.ApplicationMenu;

            //加入分类线
            Autodesk.Windows.RibbonSeparator acRs = new RibbonSeparator();
            acAppMenu.MenuContent.Items.Add(acRs);

            //增加主菜单“WLAN”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt0 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt0.Text = "WLAN";
            acAppMenuIt0.Description = " ";

            //增加“WLAN”的子菜单“图形工具”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt00 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt00.Text = "图形工具";

            //增加“图形工具”的子菜单“设备”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt000 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt000.Text = "设备";
            acAppMenuIt00.Items.Add(acAppMenuIt000);
            //增加“图形工具”的子菜单“无源器件”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt001 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt001.Text = "无源器件";
            acAppMenuIt00.Items.Add(acAppMenuIt001);
            //增加“图形工具”的子菜单“天线”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt002 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt002.Text = "天线";
            acAppMenuIt00.Items.Add(acAppMenuIt002);
            //增加“图形工具”的子菜单“线缆”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt003 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt003.Text = "线缆";
            acAppMenuIt00.Items.Add(acAppMenuIt003);

            acAppMenuIt0.Items.Add(acAppMenuIt00);

            //增加“WLAN”的子菜单“覆盖分析”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt01 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt01.Text = "覆盖分析";

            //增加“覆盖分析”的子菜单“图层设定”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt010 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt010.Text = "图层设定";
            acAppMenuIt01.Items.Add(acAppMenuIt010);
            //增加“覆盖分析”的子菜单“图纸修正”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt011 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt011.Text = "图纸修正";
            acAppMenuIt01.Items.Add(acAppMenuIt011);
            //增加“覆盖分析”的子菜单“扫描分析”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt012 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt012.Text = "扫描分析";
            acAppMenuIt01.Items.Add(acAppMenuIt012);

            acAppMenuIt0.Items.Add(acAppMenuIt01);

            //增加“WLAN”的子菜单“图纸导出”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt02 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt02.Text = "图纸导出";

            acAppMenuIt0.Items.Add(acAppMenuIt02);

            //增加“WLAN”的子菜单“系统配置”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt03 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt03.Text = "系统配置";

            //增加“系统配置”的子菜单“网络配置”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt030 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt030.Text = "网络配置";
            acAppMenuIt03.Items.Add(acAppMenuIt030);
            //增加“系统配置”的子菜单“数据下载”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt031 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt031.Text = "数据下载";
            acAppMenuIt03.Items.Add(acAppMenuIt031);
            //增加“系统配置”的子菜单“系统日志”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt032 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt032.Text = "系统日志";
            acAppMenuIt03.Items.Add(acAppMenuIt032);
            //增加“系统配置”的子菜单“修改密码”
            Autodesk.Windows.ApplicationMenuItem acAppMenuIt033 = new Autodesk.Windows.ApplicationMenuItem();
            acAppMenuIt033.Text = "修改密码";
            acAppMenuIt03.Items.Add(acAppMenuIt033);

            acAppMenuIt0.Items.Add(acAppMenuIt03);
 
            acAppMenu.MenuContent.Items.Add(acAppMenuIt0);
        }
    }
}
